import { queryDeviceTypeTree } from '@/services/api';

export default {
  namespace: 'devicetype',

  state: {
    tree: [],
  },

  effects: {
    *fetchTree(_, { call, put }) {
      const response = yield call(queryDeviceTypeTree);
      yield put({
        type: 'saveTree',
        payload: response,
      });
    },
  },

  reducers: {
    saveTree(state, action) {
      return {
        ...state,
        tree: action.payload,
      };
    },
  },
};
